<?php
  require(dirname(__FILE__).'/global.php');
  
  $email = $_POST['email'];
  if(!isset($email))
  {
      $smarty->assign('action','regist');
      $smarty->assign("code","verify.php");
      $smarty->display('passport.html');
      unset($_SESSION['post']);
  }
  else
  {
      if(isset($_SESSION['post']))
      {
          header("Location: passport.php");
      }
      $_SESSION['post'] = true;
      $sql = "select UserEmail from talking_user where UserEmail = '$email'";
      $users = $db->query($sql);
      if(count($users)>0)
      {
          echo '邮箱已经被注册！';
          exit();
      }    
      
      $userID = DataConverter::initSerialNo();
      $userName = explode('@',$email);
      $userName = $userName[0];
      $userPass = $_POST['userpass'];
      $userImg = 'static/images/default.gif';         
      $userRegistTime = DateUtil::get_YY_mm_dd_HH_mm_ss();
      $userRegistIP = $_SERVER['REMOTE_ADDR'];
      
      require(ROOT.'/include/encrypt.class.php');
      $userPass = Encrypt::encrypt($userPass);
      
      $sql = "insert into talking_user(UserID,UserName,UserEmail,UserPass,UserImg,UserRegistTime,UserRegistIP) values('$userID','$userName','$email','$userPass','$userImg','$userRegistTime','$userRegistIP')";
      $db->execute($sql);
      
      $_SESSION['user']['id'] = $userID;
      $_SESSION['user']['name'] = $userName;
      $_SESSION['user']['group'] = '1';
      
      $smarty->assign('action','success');
      $smarty->display('passport.html');
  }                             
?>
